package com.nova.bluetooth.ui.ai.translate;

import static android.util.TypedValue.COMPLEX_UNIT_SP;

import android.widget.TextView;

import androidx.annotation.NonNull;

import com.nova.bluetooth.R;
import com.nova.bluetooth.base.BaseNovaDataBindingHolder;
import com.nova.bluetooth.base.BaseNovaQuickAdapter;
import com.nova.bluetooth.base.TranslatingBean;
import com.nova.bluetooth.databinding.ItemAiTranslateBinding;


public class TranslateAdapter extends BaseNovaQuickAdapter<TranslatingBean,
        BaseNovaDataBindingHolder<ItemAiTranslateBinding>> {
    public TranslateAdapter() {
        super(R.layout.item_ai_translate);
    }

    private boolean mAdapterTypeIsBottom = true;
    public void adapterTypeIsBottom(boolean isBottom){
        mAdapterTypeIsBottom = isBottom;
    }

    private boolean isSpeakingView = true;
    public void  resetTextColorByUser(boolean isSpeakingView){
        this.isSpeakingView = isSpeakingView;
        notifyDataSetChanged();
    }

    @Override
    public void onBindViewHolder(@NonNull BaseNovaDataBindingHolder<ItemAiTranslateBinding> holder, int position) {
        super.onBindViewHolder(holder, position);
        TextView textView = (TextView) holder.getView(R.id.tv_text);
        if (getItemCount() - 1 == position) {
            holder.setTextColorRes(R.id.tv_text, R.color.black);
            textView.setTextSize(COMPLEX_UNIT_SP, 25);
        } else {
            if (isSpeakingView){
                holder.setTextColorRes(R.id.tv_text, R.color.translate_text_color3);
            }else {
                holder.setTextColorRes(R.id.tv_text, R.color.translate_text_color2);
            }
            textView.setTextSize(COMPLEX_UNIT_SP, 18);
        }
    }

    @Override
    protected void convert(@NonNull BaseNovaDataBindingHolder<ItemAiTranslateBinding> holder, TranslatingBean data) {
        ItemAiTranslateBinding dataBinding = holder.getDataBinding();
        if (mAdapterTypeIsBottom){
            holder.setText(R.id.tv_text, data.getBottomContent());
        }else {
            holder.setText(R.id.tv_text, data.getTopContent());
        }
        dataBinding.executePendingBindings();
    }

}
